package com.linhh.mall.center.web.controller;

import com.linhh.mall.center.api.RoleInfoService;
import com.linhh.mall.center.api.UserInfoService;
import com.linhh.mall.center.common.pojo.RoleInfo;
import com.linhh.mall.center.common.pojo.UserInfo;
import com.linhh.mall.center.common.util.SecurityUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author linhh
 * @Date 2022 10 19 15 25
 **/
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Reference
    private UserInfoService userInfoService;

    @Reference
    private RoleInfoService roleinfoService;

    @GetMapping(value = "/info/{type}")
    public ResponseEntity<Object> getUserInfo(@PathVariable Integer type) {
        UserInfo userInfo = userInfoService.findByUserName(SecurityUtils.getUserName());
        List<RoleInfo> roleInfoList = roleinfoService.selectRoleByUserId(userInfo.getId());
        userInfo.setRoleList(roleInfoList);
        return ResponseEntity.ok(userInfo);
    }

}
